<template>
  <div>
    <avue-crud
      ref="crud"
      v-model="form"
      :option="option"
      :table-loading="listLoading"
      :before-open="handleOpenBefore"
      :data="list"
      @on-load="getList"
      @row-update="update"
      @search-change="getList"
      @refresh-change="getList"
    >
    </avue-crud>
  </div>
</template>

<script>
// import { doGet, doPost, doDelet, doPut } from '@/router/axios'
import { formCreate } from "@/api/index"
export default {
  name: "tableColumn",
  props: {
    tableID: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      listLoading: true,
      list: [],
      form: {},
      option: {
        // index:true,
        // indexLabel:'序号',
        resizable: true,
        align: "center",
        menuAlign: "center",
        border: true,
        menu: false,
        dialogFullscreen: true,
        addBtn: false,
        editBtn: true,
        delBtn: false,
        addRowBtn: false,
        refreshBtn: true,
        menuWidth: 120,
        column: [
          {
            fix: true,
            label: "表单主键",
            prop: "tableId",
            span: 24,
            hide: true,
            editDisplay: false,
          },
          {
            fix: true,
            label: "主键",
            prop: "id",
            span: 24,
            hide: true,
            editDisplay: false,
          },
          {
            fix: false,
            label: "字段名称",
            prop: "columnName",
            width: 120,
            hide: false,
          },
          {
            label: "字段描述",
            prop: "columnDes",
            editDisplay: true,
          },
          {
            label: "字段类型",
            prop: "columnType",
          },
          {
            label: "显示排序",
            prop: "columnSort",
          },
          {
            label: "输入框类型",
            type: "select",
            width: 95,
            dicUrl: '/api-sys/sys/dict/autoCache/D000013',
            prop: "columnInputType",
          },
          {
            label: "校验类型",
            type: "select",
            dicUrl: '/api-sys/sys/dict/autoCache/D000015',
            prop: "columnValidateType",
          },
          {
            label: "是否隐藏",
            prop: "isHidde",
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "是否新增",
            prop: "isAdd",
            type: "select",
            dicUrl: '/api-sys/sys/dict/autoCache/D000009',
          },
          {
            fix: true,
            label: "是否新增必填",
            labelWidth: 120,
            prop: "isAddRequired",
            width: 95,
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "是否编辑",
            prop: "isEdit",
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "是否编辑必填",
            labelWidth: 120,
            prop: "isEditRequired",
            width: 95,
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "是否搜索",
            prop: "isSelect",
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "搜索类型",
            prop: "selectType",
            type: "select",
            dicUrl: '/api-sys/sys/dict/autoCache/D000014',
          },
          {
            label: "是否增强",
            prop: "isStrong",
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "增强参数",
            prop: "",
          },
          {
            label: "最小长度",
            prop: "cloumnMin",
          },
          {
            label: "最大长度",
            prop: "columnMax",
          },
          {
            label: "是否主键",
            prop: "isPrincipal",
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "是否导出",
            prop: "isExport",
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "是否使用字典",
            labelWidth: 120,
            prop: "isDict",
            width: 95,
            type: "select",
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "字典编码",
            prop: "dictCode",
          },
        ],
      },
    };
  },
  methods: {
    getList() {
      const params = {
        tableID: this.tableID,
      };
      // doGet("/online/tableColumn/getColumnsByTableId", params).then((res) => {
      //   this.list = res.data.data;
      //   this.listLoading = false;
      // });
        formCreate.getColumnsByTableId(params).then((res) => {
        this.list = res.data;
        this.listLoading = false;
      });
    },
    update(row, index, done, loading) {
      // doPost("/online/tableColumn/update", this.form)
      //   .then((res) => {
      //     if (res.data.code == 200) {
      //       this.getList();
      //       done();
      //       this.$message.success("更新成功");
      //       return;
      //     } else {
      //       this.$message.error(res.msg);
      //       return;
      //     }
      //     loading();
      //   })
      //   .catch(() => {
      //     loading();
      //   });
       formCreate.tableColumnUpdate(this.form)
        .then((res) => {
          if (res.code == 200) {
            this.getList();
            done();
            this.$message.success("更新成功");
            return;
          } else {
            this.$message.error(res.msg);
            return;
          }
          loading();
        })
        .catch(() => {
          loading();
        });
    },
    handleOpenBefore(show, type) {
      window.boxType = type;
      if (["edit", "views"].includes(type)) {
      } else if (type === "add") {
      }
      show();
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/.el-table__body-wrapper::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  background-color: #f5f5f5;
}

/*定义滚动条轨道 内阴影+圆角*/
/deep/.el-table__body-wrapper::-webkit-scrollbar-track {
  /*-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);*/
  /*border-radius: 10px;*/
  /*background-color: #F5F5F5;*/
}

/*定义滑块 内阴影+圆角*/
/deep/.el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 10px;
  /*-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .3);*/
  background-color: rgba(144, 147, 153, 0.3);
}
</style>
